package io.renren.modules.app.controller;

import com.google.gson.Gson;
import io.renren.common.utils.AESUtil;
import io.renren.common.utils.R;
import io.renren.modules.app.request.BdcJfQueryRequest;
import io.renren.modules.app.request.InsertTysJsxxRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.awt.*;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Api(tags = "分行系统接口")
@RestController
@RequestMapping("/immovablespay/ivpay")
public class TestController {


    //    /**
//     * 银行缴费查询接口
//     */
//    @PostMapping("bdcJfQuery")
//    @ApiOperation("银行缴费查询接口")
//    @ResponseBody
    @RequestMapping(value = "/BdcJfQuery", method = RequestMethod.POST)
    public String BdcJfQuery(String ywh) {

        try {
            String str = "{\"rspcode\":\"200\",\"state\":\"success\",\"rspmsg\":{\"是否缴费\":\"N\",\"权利人证件号\":null,\"权利人电话\":\"12345678\",\"PID\":82592,\"权利人名称\":\"123\",\"业务号\":\"HNBQ2019000005\",\"应缴金额\":80,\"区属\":\"汉南区\"},\"order_id\":\"12345678\",\"mac\":\"********\"}";

            String str1 = AESUtil.Encrypt(str, "1234567891234567");

            String Str2 = URLEncoder.encode(str1, "UTF-8");

            return Str2;
        } catch (Exception e) {
            return "";
        }
    }

    @RequestMapping(value = "/getTransforKey", method = RequestMethod.POST)
    public String getTransforKey(String Busi_code, String City_code, String Unit_code) {
        try {
            String str = "{\"rspcode\": \"200\",\"rspmsg\": \"获取MAC秘钥成功\",\"transkey\": \""
                    + URLEncoder.encode(AESUtil.encrypt("1234567891234567"), "UTF-8") + "\"}";

//            String str1 = AESUtil.encrypt(str);
//
//            String Str2 = URLEncoder.encode(str1, "UTF-8");
            return str;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";

    }

    @RequestMapping(value = "/getMacKey", method = RequestMethod.POST)
    public String getMacKey(String Busi_code, String City_code, String Unit_code) {
        try {
            String str = "{\"rspcode\": \"200\",\"rspmsg\": \"获取MAC秘钥成功\",\"mackey\": \""
                    + URLEncoder.encode(AESUtil.Encrypt("123456", "1234567891234567"), "UTF-8") + "\"}";

//            String str1 = AESUtil.encrypt(str);
//
//            String Str2 = URLEncoder.encode(str1, "UTF-8");
            return str;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";

    }

    /**
     * 银行缴费查询接口
     */
    @PostMapping("bdcJfQuery")
    @ApiOperation("银行缴费查询接口")
    @ResponseBody
    public Map bdcJfQuery(@Valid @RequestBody BdcJfQueryRequest request) {

        Map map = new HashMap();

        if (true) {
            map.put("rspcode", "400");
            map.put("rspmsg", "账号验证失败");

        } else {
            map.put("rspcode", "200");
            map.put("rspmsg", "success");
            Map msg = new HashMap();
            msg.put("是否缴费", "N");
            msg.put("权利人证件号", null);
            msg.put("权利人电话", "1300000000");
            msg.put("PID", 82592);
            msg.put("权利人名称", "张三");
            msg.put("业务号", "HNBQ2019000005");
            msg.put("应缴金额", 0.01);
            msg.put("区属", "汉南区");
            map.put("rspmsg", msg);

        }

        return map;
    }

    /**
     * 银行缴费查询接口
     */
    @PostMapping("insertTysJsxx")
    @ApiOperation("不动产银行缴费数据更新接口")
    @ResponseBody
    public Map insertTysJsxx(@Valid @RequestBody InsertTysJsxxRequest request) {
        Map map = new HashMap();

        if (true) {

            map.put("rspcode", "200");
            map.put("rspmsg", "缴费数据记录成功");

        } else {
            map.put("rspcode", "400");
            map.put("rspmsg", "账号验证失败");
        }

        return map;
    }


    /**
     * 银行缴费查询接口
     */
    @PostMapping(value = "upLoadBillFile", consumes = {"multipart/form-data"})
    @ApiOperation("上传图片")
    @ResponseBody
    public Map upLoadBillFile(@RequestParam("billfile") MultipartFile billfile, String sig) {
        Map map = new HashMap();

        if (true) {
            System.out.println("-----------------------------------------------" + sig);
            map.put("rspcode", "200");
            map.put("rspmsg", "缴费数据记录成功");

        } else {
            map.put("rspcode", "400");
            map.put("rspmsg", "账号验证失败");
        }
        return map;
    }
}
